<?php
//查询队伍数据
$params = json_decode(file_get_contents("php://input"), true);
if ($_SERVER["REQUEST_METHOD"] == "POST") {
  $teamName = $params['teamName'];
}

include('../mysqli_connect.php');
if ($teamName == '') {
  $sql = "SELECT a.*,b.team_name t1,c.team_name t2 FROM game a INNER JOIN team b ON a.home_team_id = b.team_id INNER JOIN team c ON a.guest_team_id = c.team_id;";
} else {
  $sql = "SELECT a.*,b.team_name t1,c.team_name t2 FROM game a INNER JOIN team b ON a.home_team_id = b.team_id INNER JOIN team c ON a.guest_team_id = c.team_id where b.team_name like '%{$teamName}%' or c.team_name like '%{$teamName}%' or a.group_no like '%{$teamName}%';";
}

$res = mysqli_query($dbc, $sql);
if (!$res) {
  printf("Error: %s\n", mysqli_error($dbc));
  exit();
}
if ($res) {
  // 查询成功
  $resultArray = array();
  $i = 0;
  while ($row = mysqli_fetch_row($res)) {
    // $resultArray[] = $row;
    $resultArray[$i]['gameId'] = $row[0];
    $resultArray[$i]['hId'] = $row[1];
    $resultArray[$i]['gId'] = $row[2];
    $resultArray[$i]['hScore'] = $row[3];
    $resultArray[$i]['gScore'] = $row[4];
    $resultArray[$i]['type'] = $row[5];
    $resultArray[$i]['group'] = $row[6];
    $resultArray[$i]['begin'] = $row[7];
    $resultArray[$i]['end'] = $row[8];
    $resultArray[$i]['logo'] = $row[9];
    $resultArray[$i]['comment'] = $row[10];
    $resultArray[$i]['t1'] = $row[12];
    $resultArray[$i]['t2'] = $row[13];
    $i = $i + 1;
  }
  $response = array('status' => true, 'message' => '查询数据成功', 'data' => $resultArray, 'sql' => $sql);
  echo json_encode($response);
} else {
  $response = array('status' => false, 'message' => '查询数据失败', 'data' => $resultArray);
  echo json_encode($response);
}
